#include <REGX52.H>
#include "DELAY.H"

unsigned char MatirxKey()
{
	unsigned char keynumber=0;
	P1=0Xff;
	P1_3=0;
	if(P1_7==0){Delay(15);while(P1_7==0);Delay(15);keynumber=1;}
	if(P1_6==0){Delay(15);while(P1_6==0);Delay(15);keynumber=5;}
	if(P1_5==0){Delay(15);while(P1_5==0);Delay(15);keynumber=9;}
	if(P1_4==0){Delay(15);while(P1_4==0);Delay(15);keynumber=13;}
	
	P1=0Xff;
	P1_2=0;
	if(P1_7==0){Delay(15);while(P1_7==0);Delay(15);keynumber=2;}
	if(P1_6==0){Delay(15);while(P1_6==0);Delay(15);keynumber=6;}
	if(P1_5==0){Delay(15);while(P1_5==0);Delay(15);keynumber=10;}
	if(P1_4==0){Delay(15);while(P1_4==0);Delay(15);keynumber=14;}
	
	P1=0Xff;
	P1_1=0;
	if(P1_7==0){Delay(15);while(P1_7==0);Delay(15);keynumber=3;}
	if(P1_6==0){Delay(15);while(P1_6==0);Delay(15);keynumber=7;}
	if(P1_5==0){Delay(15);while(P1_5==0);Delay(15);keynumber=11;}
	if(P1_4==0){Delay(15);while(P1_4==0);Delay(15);keynumber=15;}
	
	P1=0Xff;
	P1_0=0;
	if(P1_7==0){Delay(15);while(P1_7==0);Delay(15);keynumber=4;}
	if(P1_6==0){Delay(15);while(P1_6==0);Delay(15);keynumber=8;}
	if(P1_5==0){Delay(15);while(P1_5==0);Delay(15);keynumber=12;}
	if(P1_4==0){Delay(15);while(P1_4==0);Delay(15);keynumber=16;}
	
	
	
	
	return keynumber;
	
}